 // pages/fileDetail/fileDetail.js
Page({
    data: {
      activeTab: 'overview', // 当前激活的标签页
      fileInfo: {
        id: 'DOC836725',
        name: '合同文件.pdf',
        status: 'completed',
        statusText: '已完成',
        priority: '高优先',
        size: '2.3MB',
        pages: '10页',
        creator: '张三',
        category: '合同文件',
        contact: '13800138000',
        department: '法务部',
        copies: '1份',
        colorMode: '黑白',
        paperSize: 'A4',
        duplex: '单面',
        uploadTime: '2025-05-19 16:03:01',
        printTime: '2025-05-13 22:50:36',
        starred: false
      },
      traceSteps: [
        {
          id: 1,
          title: '文件上传',
          time: '2025-05-19 16:03:01',
          description: '用户通过移动端上传文档',
          operator: '张三',
          device: '移动端APP',
          ip: '192.168.1.100',
          status: 'completed'
        },
        {
          id: 2,
          title: '安全扫描',
          time: '2025-05-19 16:03:15',
          description: '文档安全性检查通过',
          operator: '系统',
          device: '安全部务器',
          ip: '10.0.0.50',
          status: 'completed'
        },
        {
          id: 3,
          title: '权限审核',
          time: '2025-05-19 16:05:12',
          description: '文档打印权限审核通过',
          operator: '李经理',
          device: '管理端',
          ip: '192.168.1.200',
          status: 'completed'
        },
        {
          id: 4,
          title: '开始打印',
          time: '2025-05-13 22:50:36',
          description: '文档发送至打印机开始打印',
          operator: '张三',
          device: '办公室A-打印机01',
          ip: '192.168.1.150',
          status: 'completed'
        },
        {
          id: 5,
          title: '打印完成',
          time: '2025-05-13 22:52:15',
          description: '文档打印任务完成',
          operator: '系统',
          device: '办公室A-打印机01',
          ip: '192.168.1.150',
          status: 'completed'
        }
      ],
      logRecords: [
        {
          id: 1,
          user: '张三',
          action: '查看',
          time: '2025-05-19 16:03:01',
          ip: '192.168.1.100'
        },
        {
          id: 2,
          user: '李经理',
          action: '制检',
          time: '2025-05-19 16:05:12',
          ip: '192.168.1.200'
        },
        {
          id: 3,
          user: '王助理',
          action: '下载',
          time: '2025-05-20 10:30:00',
          ip: '192.168.1.180'
        }
      ]
    },
  
    onLoad: function (options) {
      // 获取传递的文件ID
      const fileId = options.id;
      if (fileId) {
        this.loadFileDetail(fileId);
      }
    },
  
    // 加载文件详情
    loadFileDetail: function(fileId) {
      // 这里应该调用API获取文件详情
      // 暂时使用模拟数据
      const mockData = {
        '1': {
          id: 'CT2025051001',
          name: '合同文件.pdf',
          status: 'completed',
          statusText: '已完成',
          priority: '高优先',
          size: '2.3MB',
          pages: '10页',
          creator: '张三',
          category: '合同文件',
          contact: '13800138000',
          department: '法务部',
          copies: '1份',
          colorMode: '黑白',
          paperSize: 'A4',
          duplex: '单面',
          uploadTime: '2025-05-19 16:03:01',
          printTime: '2025-05-10 14:30:00',
          starred: false
        },
        '2': {
          id: 'DOC836726',
          name: '财务报表.xlsx',
          status: 'processing',
          statusText: '打印中',
          priority: '中优先',
          size: '1.8MB',
          pages: '5页',
          creator: '李四',
          category: 'Excel文件',
          contact: '13900139000',
          department: '财务部',
          copies: '2份',
          colorMode: '彩色',
          paperSize: 'A4',
          duplex: '双面',
          uploadTime: '2025-05-19 15:45:22',
          printTime: '2025-05-13 21:30:15',
          starred: true
        },
        '3': {
          id: 'DOC836727',
          name: '项目计划书.docx',
          status: 'pending',
          statusText: '待处理',
          priority: '高优先',
          size: '2.5MB',
          pages: '8页',
          creator: '王五',
          category: 'Word文档',
          contact: '13700137000',
          department: '项目部',
          copies: '1份',
          colorMode: '黑白',
          paperSize: 'A4',
          duplex: '单面',
          uploadTime: '2025-05-19 10:25:17',
          printTime: '2025-05-12 09:15:32',
          starred: true
        },
        '4': {
          id: 'DOC836728',
          name: '产品演示.pptx',
          status: 'completed',
          statusText: '已完成',
          priority: '低优先',
          size: '5.2MB',
          pages: '25页',
          creator: '赵六',
          category: 'PPT文件',
          contact: '13600136000',
          department: '市场部',
          copies: '3份',
          colorMode: '彩色',
          paperSize: 'A4',
          duplex: '单面',
          uploadTime: '2025-05-19 14:35:56',
          printTime: '2025-05-14 15:20:45',
          starred: false
        }
      };
  
      const fileInfo = mockData[fileId] || this.data.fileInfo;
      
      // 根据不同文件ID设置不同的溯源数据
      const traceData = {
        '1': [
          {
            id: 1,
            title: '文件上传',
            time: '2025-05-19 16:03:01',
            description: '用户通过移动端上传文档',
            operator: '张三',
            device: '移动端APP',
            ip: '192.168.1.100',
            status: 'completed'
          },
          {
            id: 2,
            title: '安全扫描',
            time: '2025-05-19 16:03:15',
            description: '文档安全性检查通过',
            operator: '系统',
            device: '安全部务器',
            ip: '10.0.0.50',
            status: 'completed'
          },
          {
            id: 3,
            title: '权限审核',
            time: '2025-05-19 16:05:12',
            description: '文档打印权限审核通过',
            operator: '李经理',
            device: '管理端',
            ip: '192.168.1.200',
            status: 'completed'
          },
          {
            id: 4,
            title: '开始打印',
            time: '2025-05-10 14:30:00',
            description: '文档发送至打印机开始打印',
            operator: '张三',
            device: '办公室A-打印机01',
            ip: '192.168.1.150',
            status: 'completed'
          },
          {
            id: 5,
            title: '打印完成',
            time: '2025-05-10 14:32:15',
            description: '文档打印任务完成',
            operator: '系统',
            device: '办公室A-打印机01',
            ip: '192.168.1.150',
            status: 'completed'
          }
        ],
        '2': [
          {
            id: 1,
            title: '文件上传',
            time: '2025-05-19 15:45:22',
            description: '用户通过Web端上传Excel文件',
            operator: '李四',
            device: 'Web管理端',
            ip: '192.168.1.105',
            status: 'completed'
          },
          {
            id: 2,
            title: '格式验证',
            time: '2025-05-19 15:45:35',
            description: 'Excel文件格式验证通过',
            operator: '系统',
            device: '文件服务器',
            ip: '10.0.0.60',
            status: 'completed'
          },
          {
            id: 3,
            title: '正在打印',
            time: '2025-05-13 21:30:15',
            description: '文档正在打印处理中',
            operator: '李四',
            device: '办公室B-打印机02',
            ip: '192.168.1.155',
            status: 'processing'
          }
        ]
      };
      
      const traceSteps = traceData[fileId] || this.data.traceSteps;
      
      // 根据不同文件ID设置不同的日志数据
      const logData = {
        '1': [
          {
            id: 1,
            user: '张三',
            action: '查看',
            time: '2025-05-19 16:03:01',
            ip: '192.168.1.100'
          },
          {
            id: 2,
            user: '李经理',
            action: '制检',
            time: '2025-05-19 16:05:12',
            ip: '192.168.1.200'
          },
          {
            id: 3,
            user: '王助理',
            action: '下载',
            time: '2025-05-20 10:30:00',
            ip: '192.168.1.180'
          }
        ],
        '2': [
          {
            id: 1,
            user: '李四',
            action: '上传',
            time: '2025-05-19 15:45:22',
            ip: '192.168.1.105'
          },
          {
            id: 2,
            user: '财务主管',
            action: '审核',
            time: '2025-05-19 16:20:15',
            ip: '192.168.1.210'
          },
          {
            id: 3,
            user: '李四',
            action: '打印',
            time: '2025-05-13 21:30:15',
            ip: '192.168.1.105'
          }
        ]
      };
      
      const logRecords = logData[fileId] || this.data.logRecords;
      
      this.setData({
        fileInfo: fileInfo,
        traceSteps: traceSteps,
        logRecords: logRecords
      });
    },
  
    
  
    // 切换标签页
    switchTab: function(e) {
      const tab = e.currentTarget.dataset.tab;
      this.setData({
        activeTab: tab
      });
    },
  
    // 复制联系方式
    copyContact: function() {
      wx.setClipboardData({
        data: this.data.fileInfo.contact,
        success: () => {
          wx.showToast({
            title: '已复制到剪贴板',
            icon: 'success',
            duration: 1500
          });
        }
      });
    },
  
    // 下载文件
    downloadFile: function() {
      wx.showLoading({
        title: '下载中...'
      });
      
      // 模拟下载过程
      setTimeout(() => {
        wx.hideLoading();
        wx.showToast({
          title: '下载完成',
          icon: 'success',
          duration: 2000
        });
      }, 2000);
    },
  
    // 重新打印
    reprintFile: function() {
      wx.showModal({
        title: '确认重新打印',
        content: `确定要重新打印文件"${this.data.fileInfo.name}"吗？`,
        confirmText: '确认打印',
        cancelText: '取消',
        success: (res) => {
          if (res.confirm) {
            wx.showLoading({
              title: '正在打印...'
            });
            
            // 模拟打印过程
            setTimeout(() => {
              wx.hideLoading();
              wx.showToast({
                title: '打印任务已提交',
                icon: 'success',
                duration: 2000
              });
            }, 1500);
          }
        }
      });
    },
  
    // 分享功能
    onShareAppMessage: function() {
      return {
        title: `文件详情 - ${this.data.fileInfo.name}`,
        path: `/pages/fileDetail/fileDetail?id=${this.data.fileInfo.id}`,
        imageUrl: '/images/default_user_avatar.png'
      };
    }
  });